package com.k12.user.controller;

import com.k12.user.model.entity.SysRole;
import com.k12.user.model.entity.SysUser;
import com.k12.user.model.entity.SysUserRole;
import com.k12.user.service.SysRoleService;

import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;
/**
 * 角色信息表(SysRole)表控制层
 *
 * @author makejava
 * @since 2025-07-28 20:53:09
 */
@RestController
@RequestMapping("sysRole")
public class SysRoleController {
    /**
     * 服务对象
     */
    @Resource
    private SysRoleService sysRoleService;

    /**
     * 分页查询
     *
     * @param sysRole 筛选条件
     * @param pageRequest      分页对象
     * @return 查询结果
     */
    @GetMapping("getAllRole")
    public List<SysRole> queryByPage(SysRole sysRole) {
        return this.sysRoleService.queryByPage(sysRole);
    }

    @GetMapping("getAllRoles")
    public List<SysRole> getAllRoles(@RequestParam("tenantId")String tenantId) {
        return this.sysRoleService.getAllRoles(tenantId);
    }

    /**
     * 通过主键查询单条数据
     *
     * @param id 主键
     * @return 单条数据
     */
    @GetMapping("selectOneRole")
    public SysRole queryById(@RequestParam("roleId")Long roleId,@RequestParam("tenantId")String tenantId) {
        return this.sysRoleService.queryById(roleId,tenantId);
    }

    /**
     * 新增数据
     *
     * @param sysRole 实体
     * @return 新增结果
     */
    @PostMapping("insertRole")
    public SysRole add(SysRole sysRole) {
        return this.sysRoleService.insert(sysRole);
    }

    /**
     * 编辑数据
     *
     * @param sysRole 实体
     * @return 编辑结果
     */
    @PostMapping("updateRole")
    public SysRole edit(SysRole sysRole) {
        return this.sysRoleService.update(sysRole);
    }

    /**
     * 删除数据
     *
     * @param id 主键
     * @return 删除是否成功
     */
    @GetMapping("deleteRole")
    public Boolean deleteById(Long id) {
        return this.sysRoleService.deleteById(id);
    }




    /**
     * 删除数据
     *
     * @param id 主键
     * @return 删除是否成功
     */
    @GetMapping("deleteRoleByIds")
    public Boolean deleteRoleByIds(@RequestParam("roleIds") Long[] roleIds,@RequestParam("tenantId") String tenantId) {
        return this.sysRoleService.deleteRoleByIds(roleIds,tenantId);
    }

    @PostMapping("checkRole")
    public String checkRole(SysRole sysRole) {
        return this.sysRoleService.checkRole(sysRole);
    }


    @PostMapping("selectAllocatedList")
    public List<SysUser> selectAllocatedList(SysUser sysUser) {
        return this.sysRoleService.selectAllocatedList(sysUser);
    }


    @PostMapping("unallocatedList")
    public List<SysUser> unallocatedList(SysUser sysUser) {
        return this.sysRoleService.unallocatedList(sysUser);
    }





}

